#!/bin/bash
# It requires no paswd ssh

if [ ! $# -eq 4 ]
then
   echo $0 "Usage: username manager_node manager_port mosa_dir"
   exit 1
fi

user=$1
manager_node=$2
manager_port=$3
mosa_dir=$4

#<base_dir> <port number> <manager_config dir>"
ssh -n $user@$manager_node "bash $mosa_dir/run-manager.sh $mosa_dir $manager_port $mosa_dir/manager/manager_config.cfg" &

echo sleeping 5 secs before start benefactors
sleep 5

{ while read NODE; do
	echo "Running a benefactor on $NODE"
#FIXME /tmp/benDate is harcoded. execute a sed command on the configuration file
	ssh -n $user@$NODE "cd $mosa_dir ; bash start-ben.sh /tmp/benData" &
        sleep 5
done } < /dev/stdin
